class IncidentsController < ApplicationController
  def create
    computeur = Computer.find_by_ip request.remote_ip
    incident = Incident.new do |i|
      i.computer_id = computeur.id
      i.kind = params[:kind]
      i.data = params[:data]
    end
    incident.save!
    response.headers['Location'] = "/incidents/#{incident.id}"
    render :nothing => true, :status => 201
  end
  
  def update
    Incident.find(:all, :conditions => "kind='DOWN' AND resolved_at IS NULL").each do |i|
      i.resolved_at = Date.today
      i.save!
    end
    Incident.update params[:id], :resolved_at => Date.today
    render :nothing => true, :status => 200
  end
  
  def show
    @incident = Incident.find params[:id]
    render :partial => "/incidents/show_one", :incident => @incident
  end
  
protected
  def check_already_exist(id, kind, data)
  	Incident.find :first , :conditions => [ "resolved_at IS NULL AND kind = ? AND data = ? AND computer_id = ?",kind,data,id ].nil?
  end
end

